import Vue from 'vue'

export const clearHttpRequestingList = () => {
  if (Vue.$httpRequestList && Vue.$httpRequestList.length > 0) {
    Vue.$httpRequestList.forEach(item => {
      for (let key in item) {
        item[key]()
      }
    })
    Vue.$httpRequestList = []
  }
}

/**
 * 允许某个请求可以继续进行
 * @param {string} api_id 请求的唯一ID
 */
export const allowRequest = function (api_id) {
	Vue.$httpRequestList.forEach((item, i) => {
		for (let key in item) {
			if (key === api_id) {
				Vue.$httpRequestList.splice(i, 1)
			}
		}
	})
}

/**
 * 防抖
 * @param {string} api_id - 请求唯一id
 */
export const stopRepeatRequest = function (api_id) {
	Vue.$httpRequestList.forEach(item => {
		for (let key in item) {
			if (key === api_id) {
				item[key]()
			}
		}
	})
}
